Constant = {
    contextUrl : '' ,
    //photoPath:'/static/view-img/',
    cdnContentPath:'http://a.mulan.ifanbo.com',
    photoPath:'http://a.mulan.ifanbo.com/static/view-img/',
    ctx:function (relativeURL) {
        return relativeURL;
    },
    exchangeRate:4.9,
    toAbsoluteURL: function (relativeURL) {
        return relativeURL;
    },
    dataToUnix : function(data){
        if(!data) return '' ;
        var f = data.split(' ', 2);
        var d = (f[0] ? f[0] : '').split('-', 3);
        var t = (f[1] ? f[1] : '').split(':', 3);
        return (new Date(
            parseInt(d[0], 10) || null,
            (parseInt(d[1], 10) || 1) - 1,
            parseInt(d[2], 10) || null,
            parseInt(t[0], 10) || null,
            parseInt(t[1], 10) || null,
            parseInt(t[2], 10) || null
        )).getTime() / 1000;
    },
    toBirthday:function(dateOfBirth){
        if(!dateOfBirth){
            return "" ;
        }
        var current = new Date();
        var birthday = new Date(dateOfBirth);
        var age = current.getFullYear()-birthday.getFullYear();
        var month =  current.getMonth() - birthday.getMonth() ;
        var date =  current.getDate() - birthday.getDay() ;
        var result =  0 ;
        if(month>0){
            result= age ;
        }else if(month = 0){
            if(date>=0){
                result= age ;
            }else{
                result= age-1 ;
            }
        }else{
            result= age-1 ;
        }

        if(result<0){
            result = 0 ;
        }
        return result ;
    },
    showMessage: function (content1, content2, content3) {
        $.messager.show({
            title: '提示',
            msg: content1 || content2 || content3 || "...",
            showType: 'slide',
            style: {
                right: '',
                top: document.body.scrollTop + document.documentElement.scrollTop,
                bottom: ''
            },
            timeout: 3000
        });
    },
    showConfirm:function(content,title){
        $.messager.confirm(title||'提示',content|| '您确定执行此操作', function(r){
            return r;
        });
    },
    alert:function(content,title){
        myApp.alert(content|| "...",title||"新途微助手");
    },
    alertMessage: function (content1, content2, content3) {
        myApp.alert(content1 || content2 || content3 || "...","新途微助手");
    },
    alertNotification:function(content,title){
        myApp.addNotification({
            title: title || '新途微助手',
            message: content || '这是一个包含标题和消息内容的简单通知',
            hold:3000
        });
    },
}

function deleteContent(targetId,typeId){
    $.messager.confirm('警告', '您确定删除此内容?', function (r) {
        if (r) {
            var url = '';
            if (typeId == 23) {
                url=Constant.ctx("/mulanweb/admin/ticket/delete");
            } else if (typeId == 24) {
                url=Constant.ctx("/mulanweb/admin/chartered/delete");
            }
            $.post(url,{targetId:targetId},function(info){
                if(info.ReturnCode == 1){
                    Constant.showMessage(info.AlertMessage,"操作成功");
                    $("#datagrid").datagrid("reload");
                }else{
                    Constant.showMessage(info.message,"操作失败");
                }
            })
        }
    });
}
function saveHot(targetId,typeId) {
    var para = {
        targetId:targetId,
        typeId:typeId || 24
    }
    $.post("/mulanweb/admin/hot_commodity/saveOrDelete",para,function(info){
        if(info.ReturnCode == 1){
            Constant.showMessage(info.AlertMessage,"操作成功");
            $("#datagrid").datagrid("reload");
        }else{
            Constant.showMessage(info.message,"操作失败");
        }
    })
}


